/*=====================================================================================
 * Description:
 *   The Modbus parameter structures used to define Modbus instances that
 *   can be addressed by Modbus protocol. Define these structures per your needs in
 *   your application. Below is just an example of possible parameters.
 *====================================================================================*/
#pragma once
// #include "modbus_params.h"  // for modbus parameters structures
#include "mbcontroller.h"
#include "device_controller.h"

// Enumeration of all supported CIDs for device (used in parameter definition table)
enum {
    //CID_INP_VER = 0,
	//CID_INP_INFO,
	//CID_INP_STATUS,

    CID_INP_TEMPERATURE, // 
    CID_INP_HUMIDITY,
    CID_INP_Negative_oxygen_ions,
    CID_INP_PM2_5,
    CID_INP_PM10,
    CID_COUNT,
};

typedef struct {
	int uart_num;
	int baud_rate;
	int parity;
	int tx_io_num;
	int rx_io_num;
	int rts_io_num;
}mb_app_config_t;

typedef struct {
	mb_communication_info_t comm;
	void* master_handler;
	QueueHandle_t queue_write;
	int parameter_num;
	mb_parameter_descriptor_t *parameter_descriptor;
	void *port_data;
}mb_app_t;

typedef struct
{
	int16_t cid;
	cid_value_t val;
}mb_write_msg_t;

void mb_app_task(void *arg);

void* master_get_param_data(void *handle, const mb_parameter_descriptor_t* param_descriptor);
esp_err_t mb_app_write(void *handle, mb_write_msg_t *msg);
esp_err_t mb_app_read_word(void *handle, uint8_t cid, uint16_t *val);
esp_err_t mb_app_read_float(void *handle, uint8_t cid, float *val);
esp_err_t mb_master_serial_create(mb_app_config_t * cfg, mb_app_t *mb_handle);
esp_err_t mb_master_tcp_create(mb_app_t *mb_handle);
// esp_err_t mb_app_set_descriptor(void *handle);


